﻿Public Class HScrollBarEx
    ''' <summary>
    ''' 构造器
    ''' </summary>
    ''' <remarks></remarks>
    Sub New()
        ' 此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()
        ' 在 InitializeComponent() 调用之后添加任何初始化。
        '不知道如何屏蔽滚动条的键盘时间，暂时把滚动条设置为不可获得焦点的样式
        SetStyle(Windows.Forms.ControlStyles.Selectable, False)
        Me.Maximum = 1
        Me.Minimum = 1
        Me.Value = 1
    End Sub
    ''' <summary>
    ''' 改变滚动条状态
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub ChangeScroll()
        Dim DocumentAreaWidth As Integer = Me.Width - 70
        If ExDocument.MaxWidth > DocumentAreaWidth Then
            If (ExDocument.MaxWidth - DocumentAreaWidth) Mod offsetUnit = 0 Then
                Maximum = 2 + (ExDocument.MaxWidth - DocumentAreaWidth) / offsetUnit
            Else
                Maximum = 1 + Math.Ceiling((ExDocument.MaxWidth - DocumentAreaWidth) / offsetUnit)
            End If
            Me.Value = offset / offsetUnit + 1
        Else
            '如果最大宽度小于或等于窗体宽度，则初始化滚动条
            Maximum = 1
            Value = 1
        End If
    End Sub
    ''' <summary>
    ''' 折行显示重置
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub Init()
        Me.Maximum = 1
        Me.Minimum = 1
        Me.Value = 1
    End Sub
End Class
